﻿using Api.Bll;
using Api.Model;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [EnableCors("_myAllowSpecificOrigins")]
    public class CommentController : ControllerBase
    {
        [HttpGet]
        public List<Comment> GetComment(int id, int ownerId, int postId)
        {
            Comment comment = new Comment();
            comment.id = id;
            comment.ownerId = ownerId;
            comment.postId = postId;
            comment.time = DateTime.MinValue;
            comment.text = "N/A";
            return BllFactory.GetCommentBLL().GetComment(comment);
        }
        [HttpPost]
        //返回1表示添加成功，0表示用户不存在，-1表示用户被禁言，-2表示由于其他原因添加失败
        public int InsertComment(Comment comment)
        {
            return BllFactory.GetCommentBLL().InsertComment(comment);
        }
        [HttpPut]
        public bool UpdateComment(Comment comment)
        {
            return BllFactory.GetCommentBLL().UpdateComment(comment);
        }
        [HttpDelete]
        public bool DeleteComment(int cid)
        {
            return BllFactory.GetCommentBLL().DeleteComment(cid);
        }
    }
}
